﻿<Window x:Class="AdornerTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:AdornerTest"
		xmlns:tk="http://schemas.xceed.com/wpf/xaml/toolkit"
        mc:Ignorable="d"
        Title="MainWindow" Height="600" Width="800">
	<DockPanel LastChildFill="True">
		<ToolBarTray DockPanel.Dock="Top">
			<ToolBar>
				<Button Command="New" Content="New" />
				<Button Command="Open" Content="Open" />
				<Button Command="Save" Content="Save" />
			</ToolBar>
			<ToolBar>
				<Button Command="Cut" Content="Cut" />
				<Button Command="Copy" Content="Copy" />
				<Button Command="Paste" Content="Paste" />
			</ToolBar>
			<ToolBar>
				<Button x:Name="btnAddInput" Content="Add Input" Click="btnAddInput_Click"/>
				<Button x:Name="btnAddOutput" Content="Add Output" Click="btnAddOutput_Click" />
			</ToolBar>
		</ToolBarTray>
		<!--
		##################
		PROPERTY GRID
		##################
		-->
		<tk:PropertyGrid DockPanel.Dock="Left" SelectedObject="{Binding SelectedItem}" AutoGenerateProperties="False" Width="300">
			<tk:PropertyGrid.PropertyDefinitions>
				<tk:PropertyDefinition TargetProperties="Name" Category="General"/>
				<tk:PropertyDefinition TargetProperties="Width"  Category="Position" />
				<tk:PropertyDefinition TargetProperties="Height" Category="Position" />
				<tk:PropertyDefinition TargetProperties="Top" Category="Position" />
				<tk:PropertyDefinition TargetProperties="Left" Category="Position" />
				<tk:PropertyDefinition TargetProperties="BackgroundColor" Category="Appearance"  />
				<tk:PropertyDefinition TargetProperties="Font" Category="Appearance"  />
				<tk:PropertyDefinition TargetProperties="FontSize" Category="Appearance"  />
			</tk:PropertyGrid.PropertyDefinitions>

		</tk:PropertyGrid>

		<!--
		#################
		BOUND DESIGN CANVAS
		#################
		-->
		<ItemsControl x:Name="itms" ItemsSource="{Binding AllItems}">
			<!-- ItemsControl was used so that I could bind items to the canvas using MVVM -->
			<ItemsControl.ContextMenu>
				<!-- CUT COPY PASTE MENU-->
				<ContextMenu ItemsSource="{Binding ContextItems}">
					<ContextMenu.ItemTemplate>
						<DataTemplate DataType="MenuItem">
							<MenuItem Header="{Binding Name}" Command="{Binding Action}" 
											  CommandParameter="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}"></MenuItem>
						</DataTemplate>
					</ContextMenu.ItemTemplate>
				</ContextMenu>
			</ItemsControl.ContextMenu>
			<ItemsControl.ItemsPanel>
				<ItemsPanelTemplate>
					<Canvas x:Name="mainCanvas" Background="White" IsItemsHost="True" ClipToBounds="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
					</Canvas>
				</ItemsPanelTemplate>
			</ItemsControl.ItemsPanel>
			<ItemsControl.ItemTemplate>
				<DataTemplate>
					<!-- when an item is added  to the collection, this is the template for it -->
					<ContentControl MouseDown="someItem_MouseDown" MouseUp="someItem_MouseUp"
									Background="{Binding Background}"
									Width="{Binding Width}" Height="{Binding Height}">
						<ContentControl.Resources>
							<Style TargetType="Border">
								<Setter Property="BorderBrush" Value="Purple"></Setter>
								<Setter Property="BorderThickness" Value="2"></Setter>
							</Style>
						</ContentControl.Resources>
						<ContentControl.ContextMenu>
							<ContextMenu ItemsSource="{Binding ContextItems}">
								<ContextMenu.ItemTemplate>
									<DataTemplate DataType="MenuItem">
										<MenuItem Header="{Binding Name}" Command="{Binding Action}" 
											  CommandParameter="{Binding Path=DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}}"></MenuItem>

									</DataTemplate>
								</ContextMenu.ItemTemplate>
							</ContextMenu>
						</ContentControl.ContextMenu>
						<ContentControl.Template>
							<ControlTemplate>
								<!-- TODO: use a template selector to choose what
								template to use based on the IsInput and IsOutput
								properties.  If input, show pins on right, if output 
								show pins on left.  
								
								TODO: Allow pins to be dragged to other controls
								-->
								
								<Border BorderBrush="Black" BorderThickness="1" CornerRadius="3" Loaded="Border_Loaded">
									<Border.Background>
										<LinearGradientBrush StartPoint="0.5,-0.273912" EndPoint="0.5,1.27391">
											<LinearGradientBrush.GradientStops>
												<GradientStop Color="{Binding BackgroundColor}" Offset="0"/>
												<GradientStop Color="#FFFFFDCE" Offset="1"/>
											</LinearGradientBrush.GradientStops>
										</LinearGradientBrush>
									</Border.Background>
									<Grid>
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="20"></ColumnDefinition>
											<ColumnDefinition Width="*"></ColumnDefinition>
											<ColumnDefinition Width="20"></ColumnDefinition>
										</Grid.ColumnDefinitions>
										<Grid.RowDefinitions>
											<RowDefinition Height="20"></RowDefinition>
											<RowDefinition Height="20"></RowDefinition>
											<RowDefinition Height="20"></RowDefinition>
											<RowDefinition Height="20"></RowDefinition>
											<RowDefinition Height="*"></RowDefinition>
										</Grid.RowDefinitions>


										<TextBlock Text="{Binding Name}" Grid.Column="1" Grid.RowSpan="5"
											   FontFamily="{Binding Font}" FontSize="{Binding FontSize}"
											   Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" >


										</TextBlock>
									</Grid>
								</Border>
							</ControlTemplate>
						</ContentControl.Template>
					</ContentControl>
				</DataTemplate>
			</ItemsControl.ItemTemplate>
			<ItemsControl.ItemContainerStyle>
				<Style   >
					<Setter Property="Canvas.Left" Value="{Binding Left}" />
					<Setter Property="Canvas.Top" Value="{Binding Top}" />
				</Style>
			</ItemsControl.ItemContainerStyle>
		</ItemsControl>

	</DockPanel>


</Window>
